#pragma once
#include <iostream>
#include <vector>
#include <functional>
#include <ctime>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
using work_t = std::function<void()>;
void Download()
{
    std::cout << "Download..." << getpid() << std::endl;
}
void Sql()
{
    std::cout << "Sql..." << getpid() << std::endl;
}
void Log()
{
    std::cout << "Log..." << getpid() << std::endl;
}

class Task_Mannger
{
public:
    Task_Mannger() // 默认有三个任务
    {
        srand(time(nullptr)); // 随机数种子,用于随机挑选任务
        Add_Tasks(Download);
        Add_Tasks(Sql);
        Add_Tasks(Log);
    }
    void Add_Tasks(work_t work)
    {
       tasks.push_back(work);
    }
    int Select_Tasks() // 随机选择
    {
        return rand() % tasks.size();
    }
    int Get_Size()//获取任务数
    {
        return tasks.size();
    }
    void Excubte_Tasks(int num)
    {
        if(num>tasks.size())
            return;
        else
            tasks[num]();
    }
    ~Task_Mannger()
    {
    }

private:
    std::vector<work_t> tasks;
};
Task_Mannger tsm;//全局变量任务管理员